package com.zyit.dao;

import com.zyit.DataObject.T_classify;
import com.zyit.util.BeanRowMapper;
import com.zyit.util.DBHelp;

import java.util.List;

public class T_classifyDaoSYY {
    private DBHelp dbHelp = new DBHelp();

    public List<T_classify> findClassify() throws Exception {
        String sql = "select * from t_classify";
        return dbHelp.executeQueryForList(sql, new BeanRowMapper<>(T_classify.class));

    }


    public List<T_classify> findTypeClassify(Integer type) throws Exception {
        String sql = "select * from t_classify where type = ?";
        return dbHelp.executeQueryForList(sql, new BeanRowMapper<>(T_classify.class), type);

    }

    public List<T_classify> findIdTypeClassify(Integer id) throws Exception {
        String sql = "select * from t_classify where id = ?";
        return dbHelp.executeQueryForList(sql, new BeanRowMapper<>(T_classify.class), id);

    }

    public T_classify IdTypeClassify(String id) throws Exception {
        String sql = "select * from t_classify where id = ?";
        return dbHelp.executeQueryForObject(sql, new BeanRowMapper<>(T_classify.class), id);

    }


    public List<T_classify> findNameClassify(Integer type, Integer parent_id) throws Exception {
        String sql = "select * from t_classify where type = ? and parent_id = ?";
        return dbHelp.executeQueryForList(sql, new BeanRowMapper<>(T_classify.class), type, parent_id);

    }


    public int DeleteClassify(String id) throws Exception {
        String sql = "delete from t_classify where id = ?";
        return dbHelp.executeUpdate(sql, id);
    }

    public int InsertClassfiy(String classname, String parent_id, String type) throws Exception {
        String sql = "INSERT INTO t_classify (classify_name,parent_id,type) VALUES (?,?,?)";
        return dbHelp.executeUpdate(sql, classname, parent_id, type);
    }

    public int UpdataClassify(String id, String parent_id, String type) throws Exception {
        String sql = "UPDATE t_classify SET parent_id = ?, type = ? WHERE classify_name = ?";
        return dbHelp.executeUpdate(sql, parent_id, type, id);
    }


}
